package com.villaday.idf.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.View;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.custom.foldtext.FoldTextView;
import com.villaday.idf.model.V;
import com.villaday.idf.model.Villages_commentsEntity;
import com.villaday.idf.model.house_materialEntity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import byc.imagewatcher.MessagePicturesLayout;

/**
 * 评论列表
 */

public class CommentsAdapter extends AbsRecyclerViewAdapter<Villages_commentsEntity.BodyEntity.ListEntity> {
    private OnAdapterCallbackListener onAdapterCallbackListener;
    private View.OnClickListener onClickListener;
    private MessagePicturesLayout.Callback mCallback;
    private final SimpleDateFormat format;
    private final SimpleDateFormat formatNew;

    public CommentsAdapter(Context context, OnAdapterCallbackListener onAdapterCallbackListener, View.OnClickListener onClickListener) {
        super(context, R.layout.item_fa, R.layout.item_page_loading,
                R.layout.item_page_bottom);
        this.onAdapterCallbackListener = onAdapterCallbackListener;
        this.onClickListener = onClickListener;
        format = new SimpleDateFormat("yyyy-MM-dd");
        formatNew = new SimpleDateFormat("yyyy/MM/dd");
    }

    public CommentsAdapter setPictureClickCallback(MessagePicturesLayout.Callback callback) {
        mCallback = callback;
        return this;
    }

    @Override
    public int getItemType(Villages_commentsEntity.BodyEntity.ListEntity d) {
        return d.getType();
    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, final Villages_commentsEntity.BodyEntity.ListEntity d, int position) {
        // 一般来讲， ImageWatcher 需要占据全屏的位置
// 如果是透明状态栏，你需要给ImageWatcher标记 一个偏移值，以修正点击ImageView查看的启动动画的Y轴起点的不正确
// 配置error图标 如果不介意使用lib自带的图标，并不一定要调用这个API
//设置指示器（默认小白点）
//设置指示器颜色
// 长按图片的回调，你可以显示一个框继续提供一些复制，发送等功能
//调用show方法前，请先调用setLoader 给ImageWatcher提供加载图片的实现
        switch (d.getType()) {

            case 0: {
                try {
                    holder.bindSimpleDraweeView(R.id.sdv_head, d.getMember().getHeadImageURL())
                            .bindTextView(R.id.tv_name, d.getMember().getNickName())
                            .bindTextView(R.id.tv_time, formatNew.format(format.parse(d.getCreateTime())));
                    //.bindTextView(R.id.tv_time,d.getTitle());
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                FoldTextView ftv = (FoldTextView) holder.getView(R.id.ftv);
                ftv.setText(d.getDetail());
                MessagePicturesLayout lPictures = (MessagePicturesLayout) holder.getView(R.id.l_pictures);
                View view = holder.getView(R.id.view);


                if (d.getImageURLs() == null||d.getImageURLs().size()==0){
                    lPictures.setVisibility(View.GONE);
                    view.setVisibility(View.VISIBLE);
                }else {
                    lPictures.setVisibility(View.VISIBLE);
                    view.setVisibility(View.GONE);

                }
                lPictures.setCallback(mCallback);
                if (d.getImageURLs() == null) {
                    List<String> da = new ArrayList<>();

                    lPictures.set(da, da);
                } else {
                    lPictures.set(d.getImageURLs(), d.getImageURLs());

                }


            }
            break;

            case 1: {
                onAdapterCallbackListener.onCallback();
            }
            break;


            //Utils.fitsSystemWindows(isTranslucentStatus, findViewById(R.id.v_fit));
        }


    }
}
